package controller;

import DAO.Book.Books;
import Service.BooksService;
import Service.BooksServiceImpl;
import org.junit.Test;


import java.sql.SQLException;
import java.util.ArrayList;

public class BooksController {
    private BooksService service=new BooksServiceImpl();
    /*
查询所有商品信息
 */
    @Test
    public void findAll() throws SQLException, ClassNotFoundException {
        ArrayList<Books> list=service.findAll();
        for(Books g:list){
            System.out.println(g);
        }
    }

    /*
    条件查询，根据GoodsNum查询商品信息
     */
    @Test
    public  void findByGoodsNum( ){
        Books g=service.findByGoodsNum("202003");
        System.out.println(g);
    }

    /*
    新增商品信息
     */
    @Test
    public  void insert( ){
        Books gds=new Books("202001","Java程序设计","56","2021-10-19","编程参考书","330");
       int result=service.insert(gds);
        if(result!=0){
            System.out.println("添加成功！");
        }else{
            System.out.println("添加失败！");
        }
    }

    /*
    修改商品信息
     */
    @Test
    public  void updata(){
        Books g=service.findByGoodsNum("202005");
        g.setBoodsName("钢笔");
        int result=service.updata(g);
        if(result!=0){
            System.out.println("修改成功！");
        }else{
            System.out.println("修改失败！");
        }
    }

    /*
    删除商品信息
     */
    @Test
    public  void delete( ){
        int result=service.delete("202005");
        if(result!=0){
            System.out.println("删除成功！");
        }else{
            System.out.println("删除失败！");
        }
    }
}
